define(function() {
	return function($compile, $scope) {
		require(
				[ "AppPathDir/spots/spotsTicket/support",
						"AppPathDir/spots/spotsTicket/add",
						"AppPathDir/spots/spotsTicket/update",
						"PDUtilDir/util", "PDUtilDir/tool", "PDUtilDir/inputSelect" ],
				function(Support, AddSupport, UpdateSupport, Util, Tool, inputSelect) {
					/* 查询 start */
					$scope.cache = {
						spotArray: new Array(),
						typeArray: new Array(),
						typeMap: new Map()
					};
					$scope.search = {}
					$scope.searchSupport = {
						run : function() {
							$scope.grid.reload({
								queryParam : $scope.search
							})
						}
					};
					/* 查询 end */
					$scope.addSupport = AddSupport($scope, $compile);
					$scope.updateSupport = UpdateSupport($scope, $compile);

					$scope.delSupport = {
						run : function() {
							var selectRows = $scope.grid.getSelectedRow();
							if (null != selectRows) {
								Util.confirm("是否要删除", function() {
									var ids = new Array();
									$.each(selectRows, function(index, selectRow) {
										ids.push(selectRow.id);
									});
									$.ajax({
										url : getServer() + "/flea/hclv/spotTicket/deleteByIds.htmls",
										method : 'post',
										data : {
											'ids' : JSON.stringify(ids)
										},
										success : function(
												data) {
                                            if (data.status != 200) {
                                                return;
                                            }
											$scope.grid.refresh();
											Util.alert(data.message);
										}
									});

								});
							} else {
								Util.alert('请选择要删除的数据！');
							}
						}
					};
					//景点列表
					$.ajax({
		                url:getServer()+"/flea/hclv/spot/selectMySpot.htmls",
		                success:function(data){
                            if (data.status != 200) {
                                return;
                            }
		                    $scope.cache.spotArray = data.data;
		                    inputSelect.dropCache();
		                    inputSelect({
		                        id:"spotName",
		                        key : {
		                            id : "id",
		                            name : "name",
		                            data : "data"
		                        },
		                        data : data.data,
		                        callback : function(id, data) {
		                        	$scope.search.spotId = id[0];
		                        }
		                    });
		                }
		            });
					//类型
					$.ajax({
		                url:getServer()+"/flea/dict/initTree.htmls",
		                async:false,
		                data:{'dictCode':'D_SPOT_TICKET_TYPE'},
		                success:function(data){
		                    $scope.cache.typeArray = data;
		                    $.each(data, function(index, row) {
								$scope.cache.typeMap.set(row.dictCode, row.dictName);
							});
		                    $scope.grid = Support.init($scope.cache, $scope.addSupport, $scope.updateSupport, $scope.delSupport, $scope.searchSupport);
		                }
		            });
				})
	}
});